package algotithm.leetcode.string.test1880;

/**
 * @author 25068
 * @Date 2021/6/6 10:11
 * @Title 1880. 检查某单词是否等于两单词之和
 */
public class Solution {

    public static void main(String[] args) {
        String firstWord = "acb";
        String secondWord = "cba";
        String targetWord = "cdb";
        Solution solution = new Solution();
        boolean res = solution.isSumEqual(firstWord, secondWord, targetWord);
        System.out.println(res);
    }

    public boolean isSumEqual(String firstWord, String secondWord, String targetWord) {
        String s1 = test(firstWord);
        String s2 = test(secondWord);
        String s3 = test(targetWord);
        int a = Integer.parseInt(s1);
        int b = Integer.parseInt(s2);
        int c = Integer.parseInt(s3);
        if (a + b == c) {
            return true;
        } else {
            return false;
        }

    }


    public String  test(String s) {
        StringBuilder sb  = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            sb.append(s.charAt(i) - 'a');
        }
        return sb.toString();
    }
}
